//
//  MyLocationGetter.m
//  NearPics
//
//  Created by Alex Price on 04/06/2008.
//  Copyright 2008 TheMacBox. All rights reserved.
//

#import "LocationGetter.h"

@implementation LocationGetter

@synthesize main = _main;

-(void)begin
{
	// turn on the network activity spinner in the menu bar and set up the location manager
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
	locationManager = [[CLLocationManager alloc] init];
	
	// set the delegate (ie. the thing that gets location updates) to us, set the accuracy and tell it to start updating
    locationManager.delegate = self;
    locationManager.distanceFilter = 1;  // 1 kilometer
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{	
	// Uncomment these lines to stop location updates when done (and stop the activity spinner), which you'd want in most apps really
	[manager stopUpdatingLocation];
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

	// pass coordinates back to view controller
	double lati = newLocation.coordinate.latitude+0.0;
	double longi = newLocation.coordinate.longitude+0.0;
	[self.main setCoordinate:longi latitude:lati];
}

@end
